package MediaOnline.GUI;

import MediaOnline.Data.ThongTinDienVien;
import MediaOnline.Data.filmDetail;
import MediaOnline.General.DownloadImages;
import MediaOnline.WebService.GetActorByID;
import MediaOnline.WebService.GetFilmByActorID;
import MediaOnline.WebService.GetFilmByID;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

public class actActorInfo extends Activity {

	public static TextView txtTenDienVien;
	public static TextView txtNgaySinh;
	public static TextView txtNoiSinh;
	public static TextView txtVaiTro;
	public static TextView txtCacGiaiThuong;
	public static TextView txtTieuSu;
	public static ImageView imgHinhAnh;
	public static Button btnBack;
	public static TableLayout tblFilms;
	public static int idx=0;
	public static Context ctx;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actorinfo);
		ctx = actActorInfo.this;
		//Giao dien
		txtTenDienVien = (TextView) findViewById(R.id.txtTenDienVien);
		Typeface tf = Typeface.createFromAsset(getAssets(),"font/fontTenPhimChinh.TTF");
		txtTenDienVien.setTypeface(tf);
		txtNgaySinh = (TextView) findViewById(R.id.txtNgaySinh);
		txtNoiSinh = (TextView) findViewById(R.id.txtNoiSinh);
		txtVaiTro = (TextView) findViewById(R.id.txtVaiTro);
		txtCacGiaiThuong = (TextView) findViewById(R.id.txtCacGiaiThuong);
		txtTieuSu = (TextView) findViewById(R.id.txtTieuSu);
		btnBack = (Button) findViewById(R.id.btnActorBack);
		tblFilms = (TableLayout) findViewById(R.id.tblFilms);
		imgHinhAnh = (ImageView) findViewById(R.id.imgHinhAnhActor);
		//Goi webservice lay thong tin dien vien
		GetActorByID g  = new GetActorByID(ctx);
		g.get();
		//Goi webservice lay danh sach phim cua dien vien do
		GetFilmByActorID gf = new GetFilmByActorID(ctx);
		gf.get();
		//Xu li nut back
		btnBack.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
	}
	
	
	public static void UpdateInfo()
	{
		txtTenDienVien.setText(ThongTinDienVien.Ten);
		txtNgaySinh.setText(txtNgaySinh.getText()+ThongTinDienVien.NgaySinh);
		txtNoiSinh.setText(txtNoiSinh.getText()+ThongTinDienVien.NoiSinh);
		txtVaiTro.setText(txtVaiTro.getText()+ThongTinDienVien.VaiTro);
		txtCacGiaiThuong.setText(txtCacGiaiThuong.getText()+ThongTinDienVien.CacGiaiThuong);
		txtTieuSu.setText(txtTieuSu.getText()+ThongTinDienVien.TieuSu);
		Log.d("Download actor picture::::::", ThongTinDienVien.ImgUrl);
		DownloadImages d = new DownloadImages(ctx, ThongTinDienVien.ImgUrl, imgHinhAnh);
		d.execute();
		
	}
	
	public static void UpdateListFilm(){
		//Load actor su dung lazyload
		TableRow tr = new TableRow(ctx);
		Log.d("ThongTinDienVien.lstFilmID.size()::::", ""+ThongTinDienVien.lstFilmID.size());
		for (int i = 0; i < ThongTinDienVien.lstFilmID.size(); i++) {
			idx=i;
			LinearLayout ln = new LinearLayout(ctx);
			TableRow.LayoutParams pararams =  new TableRow.LayoutParams(100,android.widget.TableRow.LayoutParams.MATCH_PARENT);
			pararams.setMargins(0, 0, 10, 0);
			ln.setLayoutParams(pararams);
			ln.setOrientation(LinearLayout.VERTICAL);
			ln.setGravity(Gravity.CENTER_VERTICAL);
			//Bat su kien click vao actor
			/*ln.setOnClickListener(new OnClickListener() {
				
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast.makeText(ctx, ActorData.lstActorID.get(idx), Toast.LENGTH_SHORT).show();
				}
			});*/
			ImageView iv = new ImageView(ctx);
			iv.setImageResource(R.drawable.movienoimg);
			iv.setPadding(0, 0, 5, 0);
			iv.setScaleType(ScaleType.FIT_CENTER);
			iv.getWidth();
			iv.setLayoutParams(new TableRow.LayoutParams(100,150));
			final String id = ThongTinDienVien.lstFilmID.get(idx);
			//Bat su kien click vao hinh anh cua actor
			//Log.d("idx::::::", ""+idx+"::::::"+ActorData.lstActorID.get(idx));
			iv.setOnClickListener(new OnClickListener() {
				
				public void onClick(View v) {
					// TODO Auto-generated method stub
					filmDetail.FilmID = id;
					ctx.startActivity(new Intent(ctx,actFilmDetailInfo2.class));
					GetFilmByID g = new GetFilmByID(ctx);
					g.get();
				}
			});
			String imgLink = ThongTinDienVien.lstFilmThumbUrl.get(idx);
			DownloadImages down = new DownloadImages(ctx, imgLink, iv);
			down.execute();
			TextView tv = new TextView(ctx);
			tv.setTextSize(12);
			tv.setText(ThongTinDienVien.lstFilmName.get(i));
			tv.setGravity(Gravity.CENTER);
			tv.setMaxLines(2);
			ln.addView(iv);
			ln.addView(tv);
			tr.addView(ln);
		}
		tblFilms.addView(tr);
	}
	
	
}
